// OScopeCtrl.h: header file
//
// Copyright (c) 2003-2007 by Daniel Strigl.
//
// The original "Oscilloscope/StripChart Control" code 
// was written by Mark C. Malburg and can be found at 
// http://www.codeproject.com/miscctrl/oscope.asp.
//
// This code may be used in compiled form in any way you desire. 
// This file may be redistributed unmodified by any means PROVIDING 
// it is not sold for profit without the authors written consent, 
// and providing that this notice and the authors name is included. 
// By the way, if the source code in this file is used in any 
// application I would appreciate and enjoy hearing about them. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage, in any form, caused
// by this code. Use it at your own risk and as with all code expect 
// bugs! It's been tested but I'm not perfect ;-)
//
// Please use the contact page of my blog to
// report any bug, comment or suggestion.
//
// Contact:
// --------
//
//   Daniel Strigl [http://geekswithblogs.net/dastblog]
//
// History:
// --------
//
//   20 Sep 2003 - Changed the original code so that it will 
//                 compile and work under Windows CE.
//
// ORIGINAL COPYRIGHT STATEMENTS:
// ------------------------------
//
//   No original copyright statements found.
//
#ifndef __OScopeCtrl_H__
#define __OScopeCtrl_H__

/////////////////////////////////////////////////////////////////////////////
// COScopeCtrl window

class COScopeCtrl : public CWnd
{
// Construction
public:
  COScopeCtrl();

// Attributes
public:
  double AppendPoint(double dNewPoint);
  void SetRange(double dLower, double dUpper, int nDecimalPlaces=1);
  void SetXUnits(CString string);
  void SetYUnits(CString string);
  void SetGridColor(COLORREF color);
  void SetPlotColor(COLORREF color);
  void SetBackgroundColor(COLORREF color);
  void InvalidateCtrl();
  void DrawPoint();
  void Reset();

  // Operations
public:

// Overrides
  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(COScopeCtrl)
  public:
  virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID=NULL);
  //}}AFX_VIRTUAL

// Implementation
public:
  int m_nShiftPixels;          // amount to shift with each new point 
  int m_nYDecimals;

  CString m_strXUnitsString;
  CString m_strYUnitsString;

  COLORREF m_crBackColor;      // background color
  COLORREF m_crGridColor;      // grid color
  COLORREF m_crPlotColor;      // data color  
  
  double m_dCurrentPosition;   // current position
  double m_dPreviousPosition;  // previous position
  bool m_bPreviousValid;		//trick to avoid jump while drawing first pixel

  virtual ~COScopeCtrl();

  // Generated message map functions
protected:
	BOOL RegisterWindowClass();
	
	//{{AFX_MSG(COScopeCtrl)
  afx_msg void OnPaint();
  afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  afx_msg void OnSize(UINT nType, int cx, int cy); 

  void OnSizeTasks();
  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()

  int m_nHalfShiftPixels;
  int m_nPlotShiftPixels;
  int m_nClientHeight;
  int m_nClientWidth;
  int m_nPlotHeight;
  int m_nPlotWidth;

  double m_dLowerLimit;        // lower bounds
  double m_dUpperLimit;        // upper bounds
  double m_dRange;
  double m_dVerticalFactor;
  
  CRect  m_rectClient;
  CRect  m_rectPlot;
  CPen   m_penPlot;
  CBrush m_brushBack;

  CDC     m_dcGrid;
  CDC     m_dcPlot;
  CBitmap *m_pbitmapOldGrid;
  CBitmap *m_pbitmapOldPlot;
  CBitmap m_bitmapGrid;
  CBitmap m_bitmapPlot;

};

/////////////////////////////////////////////////////////////////////////////

#endif // __OScopeCtrl_H__
